package com.tsmti.activiti.dao.impl;

import com.tsmti.activiti.dao.ExtendActNodeUserDao;
import com.tsmti.activiti.entity.ExtendActNodeUser;
import com.tsmti.core.common.dao.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Package：com.tsmti.activiti.dao.impl
 * @Class：ExtendActNodeuserDaoImpl
 * @Description： TODO
 * @Author：zcw
 * @Date：Created in 2018/8/16 15:49
 * @Company:
 * @Version：
 * @Modified By:
 */
@Repository("extendActNodeUserDao")
public class ExtendActNodeUserDaoImpl extends BaseDaoImpl implements ExtendActNodeUserDao {

    /**
     * 根据节点获取节点审批人员信息
     * @param nodeId
     */
    @Override
    public List<ExtendActNodeUser> getNodeUserByNodeId(String nodeId) {
        StringBuilder sql = new StringBuilder();
        sql.append("select an.*,di.name as typeName,");
        sql.append("(CASE WHEN userType='1' THEN (SELECT realname FROM pims_user u WHERE an.userNo = u.userName)");
        sql.append(" WHEN userType='2' THEN (SELECT name FROM pims_role s WHERE an.userNo = s.code)");
        sql.append(" WHEN userType='4' THEN (SELECT name FROM pims_doctorinformation d WHERE an.userNo = d.userNo)");
        sql.append(" WHEN userType='3' THEN (SELECT name FROM pims_organization o WHERE an.userNo = o.code)");
        sql.append(" WHEN userType='5' THEN an.userno  END )userTitle");
        sql.append(" from extend_act_nodeuser an  ,pims_dictionary di ,pims_dictionary_group dg ");
        sql.append(" WHERE  an.usertype = di.code and di.groupid = dg.id and dg.code='actUserType' and an.nodeId=?");
        sql.append(" and (an.delFlag =0 or an.delFlag is null)");
        return listBySql(ExtendActNodeUser.class,sql.toString(),nodeId);
    }

}
